<template>
  <div class="ChartConfig-bg" v-if="ChartsConfigFlag">
    <div class="ChartConfig-dialog">
      <div class="title">
        <p>{{ $t("message.dialog.chartConfig") }}</p>
        <i class="el-icon-close" @click="CloseDialog"></i>
      </div>
      <div class="Chart-body">
        <div class="y-view">
          <div class="y-title">{{ $t("message.dialog.y") }}</div>
          <div class="setting-view">
            <span>{{ $t("message.dialog.topMessage") }}</span>
            <div class="tool-view" style="margin-right: 28px">
              <i class="el-icon-plus" style="margin-right:6px"></i>
              <el-input v-model.number="upperLimit" class="txtRight"
                @input="upperLimit = Number(upperLimit) <= 0 ? 0 : Number(upperLimit) >= 5 ? 5 : Number(upperLimit)"></el-input>
              <span>{{ $t("message.dialog.setting") }}</span>
            </div>
          </div>
          <div class="setting-view" style="margin-top: 12px">
            <span>{{ $t("message.dialog.bottomMessage") }}</span>
            <div class="tool-view" style="margin-right: 28px">
              <i class="el-icon-minus" style="margin-right:6px"></i>
              <el-input v-model.number="lowerLimit" class="txtRight"
                @input="lowerLimit = Number(lowerLimit) <= 0 ? 0 : Number(lowerLimit) >= 5 ? 5 : Number(lowerLimit)"></el-input>
              <span>{{ $t("message.dialog.setting") }}</span>
            </div>
          </div>
        </div>
        <div class="y-view">
          <div class="y-title">{{ $t("message.dialog.x") }}</div>
          <div class="setting-view">
            <span>{{ $t("message.dialog.yearMessage") }}</span>
            <div class="tool-view">
              <el-input v-model="yearValue"
                @input="yearValue = Number(yearValue) <= 0 ? 0 : Number(yearValue) >= 10 ? 10 : Number(yearValue)"></el-input>
              <span>{{ $t("message.dialog.yearView") }}</span>
            </div>
          </div>
        </div>
        <div class="footer">
          <div class="btn-view">
            <el-button @click="CloseDialog">Cancel</el-button>
            <el-button type="primary" style="margin-left: 16px;" @click="AddChartMessage">
              OK
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSysChartConfig, addSysChartConfig } from "../../../api/api";
import { getLocalStorage } from "../../../utils/storage";
import eventBus from "../../../eventBus/bus"
// 导出模块
export default {
  props: {
    ChartsConfigFlag: Boolean,
  },
  // 模块名字
  name: "ChartConfig",
  // 模块数据
  data() {
    //数据
    return {
      upperLimit: "",
      lowerLimit: "",
      yearValue: "",
    };
  },
  // 注册组件
  components: {},
  // 监听指定值，只有指定值变化，才会触发
  watch: {},
  // 里面的函数只有调用才会执行（实时计算）里面是定义的方法
  methods: {
    AddChartMessage() {
      let dataJson = {
        userId: getLocalStorage("userID"),
        formId: "AccThckLst",
        laxisMax: String(this.upperLimit),
        laxisMin: String(this.lowerLimit),
        taxisMax: String(this.yearValue),
      };
      addSysChartConfig(dataJson).then((res) => {
        if (res.data.code != 0) {
          return;
        }

        eventBus.$emit('loadLineChart')
      }).finally(() => {
        this.CloseDialog();
      })
    },
    CloseDialog() {
      this.$emit("CloseChartsConfig");
    },
    getSysChartConfigApi() {
      let dataJson = {
        userId: getLocalStorage("userID"),
        listName: "AccThckLst",
      };
      getSysChartConfig(dataJson).then((res) => {
        if (res.data.code != 0) {
          return;
        }
        this.upperLimit = res.data.data.laxisMax;
        this.lowerLimit = res.data.data.laxisMin;
        this.yearValue = res.data.data.taxisMax;
      });
    },
  },
  // 创建前状态(里面是操作)
  beforeCreate() { },
  // 创建完毕状态(里面是操作)
  created() {
    this.getSysChartConfigApi();
  },
  // 挂载前状态(里面是操作)
  beforeMount() { },
  // 挂载结束状态(里面是操作)
  mounted() { },
  // 更新前状态(里面是操作)
  beforeUpdate() { },
  // 更新完成状态(里面是操作)
  updated() { },
  // 销毁前状态(里面是操作)
  beforeDestroy() { },
  // 销毁完成状态(里面是操作)
  destroyed() { },
};
</script>
<style lang="scss" scoped>
.ChartConfig-bg {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 666;
}

.ChartConfig-dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 488px;
  height: 342px;
  background: #ffffff;
  box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.05),
    0px 9px 28px 0px rgba(0, 0, 0, 0.08), 0px 6px 16px -8px rgba(0, 0, 0, 0.15);

  .title {
    height: 42px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    justify-content: space-between;
    font-size: 16px;
    border-bottom: 1px solid #f0f0f0;
    color: rgba(0, 0, 0, 0.85);

    .el-icon-close {
      cursor: pointer;
    }
  }

  .Chart-body {
    width: 100%;
    height: calc(100% - 42px);
  }

  .y-view {
    width: 440px;
    padding-bottom: 14px;
    border-bottom: 1px solid #f0f0f0;
    margin: 0 auto;

    .y-title {
      font-size: 16px;
      font-weight: bold;
      color: rgba(0, 0, 0, 0.85);
      padding: 16px 0 4px 0;
    }

    .setting-view {
      width: 100%;
      height: 32px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      span {
        font-size: 14px;
        color: rgba(0, 0, 0, 0.65);
      }

      .tool-view {
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
      }

      .el-input {
        width: 72px;
        margin-right: 12px;
      }

      .txtRight {
        ::v-deep .el-input__inner {
          width: 72px;
          height: 32px;
          background: #fff;
          text-align: right;
        }
      }
    }
  }

  .footer {
    width: 440px;
    margin: 0 auto;
    height: calc(100% - 226px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-direction: row-reverse;

    .btn-view {
      display: flex;
      align-items: center;
      height: 100%;
    }

    button {
      width: 82px !important;
      height: 32px;
      // background: #ffffff;
      // border: 1px solid #d9d9d9;
      // border-radius: 4px;
    }
  }
}
</style>
